using System;
using UnityEngine;

public static class Calc
{
	private static RectTransform canvasRect;

	public static int GetRealTime()
	{
		DateTime dateTime = DateTime.Now.ToLocalTime();
		return (int)(dateTime - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime()).TotalSeconds;
	}

	public static float Percentage(float CurrentNumber, float maxNumber)
	{
		return CurrentNumber / maxNumber;
	}

	public static Vector3 FindPosUsingDistAngle(float distance, float angle)
	{
		float x = distance * Mathf.Cos(angle);
		float y = distance * Mathf.Sin(angle);
		return new Vector2(x, y);
	}

	public static int KindOfWeapon(int weaponID)
	{
		if (weaponID < 7)
		{
			return weaponID;
		}
		if (weaponID % 6 == 0)
		{
			return 6;
		}
		return weaponID % 6;
	}

	public static bool IsVisibleCharacterOnScreen(Vector2 characterPos, float margin = 2f)
	{
		Vector2 vector = new Vector2(Cam.instance.tf.position.x - Cam.instance.cam.orthographicSize * 2f, Cam.instance.tf.position.y - Cam.instance.cam.orthographicSize * 2f);
		Vector2 vector2 = new Vector2(Cam.instance.tf.position.x + Cam.instance.cam.orthographicSize * 2f, Cam.instance.tf.position.y + Cam.instance.cam.orthographicSize * 2f);
		if (characterPos.x - margin > vector.x && characterPos.y - margin > vector.y && characterPos.x + margin < vector2.x && characterPos.y + margin < vector2.y)
		{
			return true;
		}
		return false;
	}

	public static bool IsEmptyField()
	{
		for (int i = 0; i < AllObjectsInfo.ArrayLength; i++)
		{
			if (AllObjectsInfo.enemy[i].hp > 0f)
			{
				return false;
			}
		}
		return true;
	}

	public static int FindEnemiesForMeleeAttack(Vector2 releasePos)
	{
		float num = 0f;
		for (int i = 0; i < AllObjectsInfo.ArrayLength; i++)
		{
			num = Vector2.Distance(releasePos, AllObjectsInfo.enemy[i].pos);
			if (num < AllObjectsInfo.enemy[i].hitSize + (float)Player.instance.basicAttackRangeWidth && AllObjectsInfo.enemy[i].hp > 0f)
			{
				return i;
			}
		}
		return -1;
	}

	public static Vector2 WorldPosToCanvasPos(Vector2 worldPos)
	{
		canvasRect = CanvasList.instance.TF_CanvasList[0];
		Vector2 vector = Camera.main.WorldToViewportPoint(worldPos);
		Vector2 result = new Vector2(vector.x * canvasRect.sizeDelta.x - canvasRect.sizeDelta.x * 0.5f, vector.y * canvasRect.sizeDelta.y - canvasRect.sizeDelta.y * 0.5f);
		return result;
	}
}
